/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

suite("agg_error_msg") {
    sql "SET enable_nereids_planner=true"
    sql "SET enable_fallback_to_original_planner=false"
    sql "DROP TABLE IF EXISTS table_20_undef_partitions2_keys3_properties4_distributed_by58;"
    sql """
        create table table_20_undef_partitions2_keys3_properties4_distributed_by58 (
        pk int,
        col_int_undef_signed int   ,
        col_int_undef_signed2 int   
        ) engine=olap
        DUPLICATE KEY(pk, col_int_undef_signed)
        distributed by hash(pk) buckets 10
        properties("replication_num" = "1");
    """

    sql "DROP TABLE IF EXISTS table_20_undef_partitions2_keys3_properties4_distributed_by53;"
    sql """
        create table table_20_undef_partitions2_keys3_properties4_distributed_by53 (
        pk int,
        col_int_undef_signed int   ,
        col_int_undef_signed2 int   
        ) engine=olap
        DUPLICATE KEY(pk, col_int_undef_signed)
        distributed by hash(pk) buckets 10
        properties("replication_num" = "1");
    """
    test {
        sql """SELECT col_int_undef_signed2   col_alias1, col_int_undef_signed  *  (SELECT  MAX (col_int_undef_signed) FROM table_20_undef_partitions2_keys3_properties4_distributed_by58 where table_20_undef_partitions2_keys3_properties4_distributed_by53.pk = pk)  AS col_alias2 FROM table_20_undef_partitions2_keys3_properties4_distributed_by53  GROUP BY  GROUPING SETS ((col_int_undef_signed2),())  ;"""
        exception "pk, col_int_undef_signed not in aggregate's output";
    }
}
